package cn.fl.finance.service.impl;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.capital.condition.CapFundQueryCondition;
import cn.fl.capital.dto.CapFundDTO;
import cn.fl.capital.service.ICapFundApiService;
import cn.fl.finance.api.IFinRepayApplyInfoApiService;
import cn.fl.finance.condition.FinRepayApplyInfoQC;
import cn.fl.finance.constant.FinFlowDynamicTableConstant;
import cn.fl.finance.constant.FinFlowFormUrlConstant;
import cn.fl.finance.constant.FinFlowModelConstant;
import cn.fl.finance.constant.FinRepayApplyInfoConstant;
import cn.fl.finance.dto.FinRepayApplyInfoDTO;
import cn.fl.finance.service.IFinRepayApplyInfoService;
import cn.fl.finance.transform.FinRepayApplyInfoVOTransform;
import cn.fl.finance.util.FlowStartParmsVO;
import cn.fl.finance.vo.FinRepayApplyInfoVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.project.api.IPrjPaySchApiService;
import cn.fl.project.condition.PrjPrdPaySchDQueryCondition;
import cn.fl.project.dto.PrjPrdPaySchDDTO;
import com.alibaba.fastjson.JSON;
import fl.flow.facade.flow.api.IFlowQueryApiService;
import fl.flow.facade.flow.condition.SysFlowSHQueryCondition;
import fl.flow.facade.flow.constant.FlowConstant;
import fl.flow.facade.flow.dto.FlowStartParamsDTO;
import fl.flow.facade.flow.dto.FlowStartedDTO;
import fl.flow.facade.flow.dto.SysFlowSHDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @Description: 还款申请信息表 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class FinRepayApplyInfoServiceImpl implements IFinRepayApplyInfoService {

	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(IFinRepayApplyInfoService.class);
	
	/**
	 * TODO 自定义 API 暴露服务
	 */
	//@Autowired
	//private I自定义ApiService 自定义ApiService;
	@Autowired
	private  IFinRepayApplyInfoApiService finRepayApplyInfoApiService;

    /**
     * 本地数据字典服务
     */
    @Autowired
    private ISysDictionaryApiService sysDictionaryApiService;

    @Autowired
    private IFlowQueryApiService flowQueryApiService;

    @Autowired
    private IPrjPaySchApiService prjPaySchApiService;

    @Autowired
    private ICapFundApiService capFundApiService;

	@Override
	public FinRepayApplyInfoVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "selectById", "主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		FinRepayApplyInfoDTO dto =  this.finRepayApplyInfoApiService.selectById(id);
		return FinRepayApplyInfoVOTransform.toVO(dto);
	}

	@Override
	public Long add(FinRepayApplyInfoVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "add", "新增对象不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		return this.finRepayApplyInfoApiService.add(FinRepayApplyInfoVOTransform.toDTO(entity));
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "removeById", "删除主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		//return this.finRepayApplyInfoApiService.removeById(id);
		//TODO 业务逻辑
		return false;
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids)throws BaseException{
    	if(CollectionUtils.isEmpty(ids)){
    		BaseLogUtils.info(logger, "removeByIds", "删除主键参数集合不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		};
		return false;
    }

	@Override
	public boolean modify(FinRepayApplyInfoVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "modify", "修改对象参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		return this.finRepayApplyInfoApiService.modify(FinRepayApplyInfoVOTransform.toDTO(entity));
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page)page = new Pager();
		//return this.finRepayApplyInfoApiService.searchListPage(page);
		//TODO 业务逻辑
		return null;
	}

	@Override
	public DataResultDTO addFlowStart(FlowStartParmsVO vo) {
		DataResultDTO result = new DataResultDTO("200");
		FlowStartParamsDTO flowStartParamsDTO = new FlowStartParamsDTO();
		try {
			flowStartParamsDTO.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_IN);
			flowStartParamsDTO.setWordsInTheTable(FinFlowDynamicTableConstant.SPL_FLOW_S_H_RPAYS);
			flowStartParamsDTO.setProcDefKey(vo.getProcDefKey());
			flowStartParamsDTO.setProcDefId(vo.getProcDefId());
			flowStartParamsDTO.setProcNo(vo.getProcNo());
			flowStartParamsDTO.setBusinessKey(vo.getId());
			flowStartParamsDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			flowStartParamsDTO.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
			flowStartParamsDTO.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());
			flowStartParamsDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
			flowStartParamsDTO.setInitiator(String.valueOf(CurrentThreadContext.getCurrentUserId()));
			flowStartParamsDTO.setInitiatorNm(CurrentThreadContext.getCurrentUserName());
			/*flowStartParamsDTO.setCrtUsrId(1l);
			flowStartParamsDTO.setOrgCd("0000");
			flowStartParamsDTO.setBuOrgCd("0000");
			flowStartParamsDTO.setSysCd("11000");
			flowStartParamsDTO.setInitiator(String.valueOf("1"));
			flowStartParamsDTO.setInitiatorNm("admin");*/
			flowStartParamsDTO.setProcPriority(FlowConstant.FLOW_PRIORITY_EMERGENCY);//优先级,可以在界面定义
			flowStartParamsDTO.setBusinessType(FinFlowDynamicTableConstant.FLOW_REPAYMENT_TABLE);//确认用不用
			flowStartParamsDTO.setModelTyp(FinFlowModelConstant.FLOW_MODEL_REPAYMENT);//需要和流程配置中的模块类型匹配
			flowStartParamsDTO.setSearchDesc(CurrentThreadContext.getCurrentOrgDispNm());
			BaseLogUtils.info(logger, "finRepayApplyInfoServiceImpl>addFlowStart", "发起借款流程->业务主键是"+vo.getId()+"请求参数是:"+JSON.toJSONString(flowStartParamsDTO));
			DataResultDTO dto = finRepayApplyInfoApiService.addFlowStart(flowStartParamsDTO);
			//
			BaseLogUtils.info(logger, "finRepayApplyInfoServiceImpl>addFlowStart", "发起借款流程->业务主键是"+vo.getId()+"返回结果是:"+JSON.toJSONString(dto));
			
			if(!dto.getCode().equals("200")){
				result.setCode(dto.getCode());
				result.setInfo(dto.getInfo());
			}
			if(dto.getCode().equals("200")){
				/*FlowStartedDTO flowStartedDTO = (FlowStartedDTO) dto.getData();
				result.setData(flowStartedDTO.getMqKey());*/
			}

		} catch (Exception e) {
			result.setCode("500");
			result.setInfo("操作失败");
			BaseLogUtils.info(logger, "addFlowStart", "借款流程操作失败信息是:"+JSON.toJSONString(e.getMessage()));
		}
		return result;
	}

    @Override
    public List<KeyValueVO> searchCdList(String grpCd) throws BaseException {
        return this.getKvList(grpCd);
    }

    @Override
    public List<FinRepayApplyInfoVO> selectPayInfoByQc(FinRepayApplyInfoQC condition) throws BaseException {
        List<FinRepayApplyInfoDTO> finRepayApplyInfoDTOS = this.finRepayApplyInfoApiService.selectPayInfoByQc(condition);
        List<FinRepayApplyInfoVO> finRepayApplyInfoVOS = FinRepayApplyInfoVOTransform.toVOList(finRepayApplyInfoDTOS);
        List<Long> payApplyIds = new ArrayList<>();//借款记录IDs
        List<Long> paySchDtlIds = new ArrayList<>();//支付表明细ids
        List<Long> allFundIds = new ArrayList<>();//所有资金IDs
        List<Long> fundIds = null;//资金IDs

        List<SysFlowSHDTO> flowSHList = new ArrayList<>();
        List<PrjPrdPaySchDDTO> prjPrdPaySchDDTOS = new ArrayList<>();
        List<CapFundDTO> capFundDTOS = new ArrayList<>();

        for (FinRepayApplyInfoVO finRepayApplyInfoVO : finRepayApplyInfoVOS) {
            payApplyIds.add(finRepayApplyInfoVO.getPayApplyId());
            paySchDtlIds.add(finRepayApplyInfoVO.getPaySchDtlId());
            fundIds = finRepayApplyInfoVO.getFundIds();
            if (CollectionUtils.isNotEmpty(fundIds)) {
                for (Long fundId : fundIds) {
                    allFundIds.add(fundId);
                }
            }
        }
        if (CollectionUtils.isNotEmpty(payApplyIds)) {
            SysFlowSHQueryCondition qc = new SysFlowSHQueryCondition();
            qc.setDataIdList(payApplyIds);
            qc.setSysCd("11000");
            qc.setWordsInTheTable("CAP");
            BaseLogUtils.info(logger, "selectPayInfoByQc", "查询流程历史API=>参数:"+JSON.toJSONString(condition));
            flowSHList = flowQueryApiService.searchFlowSHList(qc);
            BaseLogUtils.info(logger, "selectPayInfoByQc", "查询流程历史API=>结果:"+JSON.toJSONString(flowSHList));

            if (CollectionUtils.isNotEmpty(paySchDtlIds)) {
                //查询支付明细 获取 未核销金额
                PrjPrdPaySchDQueryCondition prjPrdPaySchDQueryCondition = new PrjPrdPaySchDQueryCondition();
                prjPrdPaySchDQueryCondition.setIdList(paySchDtlIds);
                BaseLogUtils.info(logger, "selectPayInfoByQc", "查询支付明细=>参数:"+JSON.toJSONString(condition));
                prjPrdPaySchDDTOS = prjPaySchApiService.selectByPaySchDtlIds(prjPrdPaySchDQueryCondition);
                BaseLogUtils.info(logger, "selectPayInfoByQc", "查询支付明细=>结果:"+JSON.toJSONString(prjPrdPaySchDDTOS));
            }
            if (CollectionUtils.isNotEmpty(allFundIds)) {
                //查询资金
                CapFundQueryCondition capFundQueryCondition = new CapFundQueryCondition();
                capFundQueryCondition.setIdList(allFundIds);
                BaseLogUtils.info(logger, "selectPayInfoByQc", "查询资金=>参数:"+JSON.toJSONString(condition));
                capFundDTOS = capFundApiService.searchCapFundList(capFundQueryCondition);
                BaseLogUtils.info(logger, "selectPayInfoByQc", "查询资金=>结果:"+JSON.toJSONString(capFundDTOS));
            }

            //费用项
            Map<String, String> loanTypCdMap = this.sysDictionaryApiService.searchGroupToMap ("11000", "0000", FinRepayApplyInfoConstant.FEE_TYP_CD);
            String cstMgrNmAndCstMgrCd = null;
            String cstMgrNm = null;
            String cstMgrCd = null;
            StringBuffer stringBuffer = null;
            List<Map <String, Object>> fundCodes = null;
            List<Long> fundIdList = null;
            for (FinRepayApplyInfoVO finRepayApplyInfoVO : finRepayApplyInfoVOS) {
                if (null != finRepayApplyInfoVO.getRepayAmt()) {
                    finRepayApplyInfoVO.setRepayAmt(finRepayApplyInfoVO.getRepayAmt() / 100);
                }
                cstMgrNm = finRepayApplyInfoVO.getCstMgrNm();
                cstMgrCd = finRepayApplyInfoVO.getCstMgrCd();
                stringBuffer = new StringBuffer();
                stringBuffer.append(cstMgrNm);
                stringBuffer.append("/");
                stringBuffer.append(cstMgrCd);
                cstMgrNmAndCstMgrCd = String.valueOf(stringBuffer);
                finRepayApplyInfoVO.setCstMgrNmAndCstMgrCd(cstMgrNmAndCstMgrCd);
                finRepayApplyInfoVO.setLoanTypCdStr(loanTypCdMap.get(finRepayApplyInfoVO.getLoanTypCd()));
                for (SysFlowSHDTO sysFlowSHDTO : flowSHList) {
                    if (Objects.equals(sysFlowSHDTO.getDataId(), finRepayApplyInfoVO.getPayApplyId())) {
                        finRepayApplyInfoVO.setpNo(sysFlowSHDTO.getPNo());//借款单号
                        finRepayApplyInfoVO.setpInstId(sysFlowSHDTO.getPInstId());//流程实例ID
                        finRepayApplyInfoVO.setAudStsCd(sysFlowSHDTO.getAudStsCd());//流程审核状态
                        finRepayApplyInfoVO.setDataId(sysFlowSHDTO.getDataId());//业务数据主键
                        finRepayApplyInfoVO.setFormUrl(FinFlowFormUrlConstant.LOAN_FORM_URL);
                    }
                }
                //未核销金额
                for (PrjPrdPaySchDDTO prjPrdPaySchDDTO : prjPrdPaySchDDTOS) {
                    if (Objects.equals(prjPrdPaySchDDTO.getId(), finRepayApplyInfoVO.getPaySchDtlId())) {
                        finRepayApplyInfoVO.setArAmt(DecimalUtils.div(prjPrdPaySchDDTO.getArAmt(), 100));//未核销金额
                    }
                }
                //资金编号
                //Long repayDtlId = finRepayApplyInfoVO.getRepayDtlId();
                fundIdList = finRepayApplyInfoVO.getFundIds();
                if (CollectionUtils.isNotEmpty(fundIdList)) {
                    fundCodes = new ArrayList<>();
                    for (Long fundId : fundIdList) {
                        for (CapFundDTO capFundDTO : capFundDTOS) {
                            if (Objects.equals(capFundDTO.getId(), fundId)) {
                                Map<String, Object> map = new HashMap<>();
                                map.put("fundId", fundId);
                                map.put("fundNm", capFundDTO.getCode());
                                fundCodes.add(map);
                            }
                        }
                    }
                    finRepayApplyInfoVO.setFundCodes(fundCodes);
                }
            }
        }

        return finRepayApplyInfoVOS;
    }

    @Override
    public List<KeyValueVO> searchCdListByLvl(String grpCd, Integer codeLvl) throws BaseException {
        List<KeyValueVO> kvList = new ArrayList<>();
        try {
            List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroupWithLevel(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), grpCd, codeLvl);
            if(CollectionUtils.isNotEmpty(sysDictionaryDTOList)){
                for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
                    KeyValueVO keyValueVO = new KeyValueVO();
                    keyValueVO.setKey(sysDictionaryDTO.getCode());
                    keyValueVO.setValue(sysDictionaryDTO.getCodeNm());
                    kvList.add(keyValueVO);
                }
            }
        } catch (BaseException e) {
            BaseLogUtils.info(logger, "getKvList", "获取字典项组"+grpCd+"失败.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception e) {
            BaseLogUtils.error(logger, "getKvList", "获取字典项组"+grpCd+"失败,系统错误.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return kvList;
    }

    @Override
    public List<KeyValueVO> searchChild(String grpCd, String acceptBkCd) throws BaseException {
        List<KeyValueVO> kvList = new ArrayList<>();
        try {
            List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchChild(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), grpCd, acceptBkCd);
            if(CollectionUtils.isNotEmpty(sysDictionaryDTOList)){
                for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
                    KeyValueVO keyValueVO = new KeyValueVO();
                    keyValueVO.setKey(sysDictionaryDTO.getCode());
                    keyValueVO.setValue(sysDictionaryDTO.getCodeNm());
                    kvList.add(keyValueVO);
                }
            }
        } catch (BaseException e) {
            BaseLogUtils.info(logger, "getKvList", "获取字典项组"+grpCd+"失败.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception e) {
            BaseLogUtils.error(logger, "getKvList", "获取字典项组"+grpCd+"失败,系统错误.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return kvList;
    }

    @Override
    public List<FinRepayApplyInfoVO> selectRepayHis(FinRepayApplyInfoQC condition) throws BaseException {
        List<FinRepayApplyInfoDTO> finRepayApplyInfoDTOS = this.finRepayApplyInfoApiService.selectRepayHis(condition);
        List<FinRepayApplyInfoVO> finRepayApplyInfoVOS = FinRepayApplyInfoVOTransform.toVOList(finRepayApplyInfoDTOS);
        List<Long> repayIds = new ArrayList<>();//还款明细ids
        for (FinRepayApplyInfoVO finRepayApplyInfoVO : finRepayApplyInfoVOS) {
            if (StringUtils.isNotEmpty(finRepayApplyInfoVO.getId())) {
                repayIds.add(finRepayApplyInfoVO.getId());
            }
        }
        List<SysFlowSHDTO> flowSHList = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(repayIds)) {
            SysFlowSHQueryCondition qc = new SysFlowSHQueryCondition();
            qc.setDataIdList(repayIds);
            qc.setSysCd("11000");
            qc.setWordsInTheTable("CAP");
            BaseLogUtils.info(logger, "searchFlowSHList", "查询流程历史API=>参数:"+JSON.toJSONString(condition));
            flowSHList = flowQueryApiService.searchFlowSHList(qc);
            BaseLogUtils.info(logger, "searchFlowSHList", "查询流程历史API=>结果:"+JSON.toJSONString(flowSHList));
        }
        for (FinRepayApplyInfoVO finRepayApplyInfoVO : finRepayApplyInfoVOS) {
            for (SysFlowSHDTO sysFlowSHDTO : flowSHList) {
                if (Objects.equals(finRepayApplyInfoVO.getId(), sysFlowSHDTO.getDataId())) {
                    finRepayApplyInfoVO.setpNo(sysFlowSHDTO.getPNo());//借款单号
                    finRepayApplyInfoVO.setpInstId(sysFlowSHDTO.getPInstId());//流程实例ID
                    finRepayApplyInfoVO.setAudStsCd(sysFlowSHDTO.getAudStsCd());//流程审核状态
                    finRepayApplyInfoVO.setDataId(sysFlowSHDTO.getDataId());//业务数据主键
                    finRepayApplyInfoVO.setFormUrl(FinFlowFormUrlConstant.REPAYMENT_FORM_URL);
                }
            }
        }

        return finRepayApplyInfoVOS;
    }

    /**
     * 根据字典中代码组值获取组员集合
     * @param grpCd 代码组值
     * @return 集合
     */
    private List<KeyValueVO> getKvList(String grpCd){
        List<KeyValueVO> kvList = new ArrayList<>();
        try {
            List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), grpCd);
            if(CollectionUtils.isNotEmpty(sysDictionaryDTOList)){
                for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
                    KeyValueVO keyValueVO = new KeyValueVO();
                    keyValueVO.setKey(sysDictionaryDTO.getCode());
                    keyValueVO.setValue(sysDictionaryDTO.getCodeNm());
                    kvList.add(keyValueVO);
                }
            }
        } catch (BaseException e) {
            BaseLogUtils.info(logger, "getKvList", "获取字典项组"+grpCd+"失败.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception e) {
            BaseLogUtils.error(logger, "getKvList", "获取字典项组"+grpCd+"失败,系统错误.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return kvList;
    }

    /**
     * 还款明细
     * @param condition
     * @return
     * @throws BaseException
     */
    @Override
    public List<FinRepayApplyInfoDTO> selectDetailList(FinRepayApplyInfoQC condition) throws BaseException {
        List<FinRepayApplyInfoDTO> finRepayApplyInfoDTOS = this.finRepayApplyInfoApiService.selectDetailList(condition);
        prepare(finRepayApplyInfoDTOS);
        return finRepayApplyInfoDTOS;
    }

    //加载数据字典数据，流程相关
    private void prepare(List<FinRepayApplyInfoDTO> finRepayApplyInfoDTOS) {
        List<SysFlowSHDTO> flowSHList = null;
        //根据还款申请id  作为主键 查询流程历史 start
        if(CollectionUtils.isNotEmpty(finRepayApplyInfoDTOS)) {
            List<Long> dataIdList  = new ArrayList<>();
            for (FinRepayApplyInfoDTO d : finRepayApplyInfoDTOS) {
                dataIdList.add(d.getId());
            }
            if(CollectionUtils.isNotEmpty(dataIdList)) {
                SysFlowSHQueryCondition condition = new SysFlowSHQueryCondition();
                condition.setDataIdList(dataIdList);
                condition.setSysCd("11000");
                condition.setWordsInTheTable("CAP");
                BaseLogUtils.info(logger, "prepare", "还款明细查询流程历史API=>参数:"+JSON.toJSONString(condition));
                flowSHList = flowQueryApiService.searchFlowSHList(condition);
                BaseLogUtils.info(logger, "prepare", "还款明细查询流程历史API=>结果:"+JSON.toJSONString(flowSHList));
            }
        }
        //根据付款明细id  作为主键 查询流程历史 end

        //还款状态
        //this.sysDictionaryApiService.getKvList(FinPayApplyInfoConstant.PAY_STS_CD, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
        Map<String, String> repayStsCdMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), FinRepayApplyInfoConstant.REPAY_STS_CD);
        //拼接数据 start
        if(CollectionUtils.isNotEmpty(finRepayApplyInfoDTOS)){
            for(FinRepayApplyInfoDTO f : finRepayApplyInfoDTOS){

                if(CollectionUtils.isMapNotEmpty(repayStsCdMap) && repayStsCdMap.containsKey(f.getRepayStsCd())){
                    f.setRepayStsCd(repayStsCdMap.get(f.getRepayStsCd()));
                }

                //流程历史填充到 付款申请信息中 strat
                if(CollectionUtils.isNotEmpty(flowSHList)) {
                    for (SysFlowSHDTO sysFlowSHDTO : flowSHList) {
                        if(sysFlowSHDTO.getDataId().equals(f.getId())) {
                            f.setpNo(sysFlowSHDTO.getPNo());
                            f.setpInstId(sysFlowSHDTO.getPInstId());
                            f.setAudStsCd(sysFlowSHDTO.getAudStsCd());
                            f.setDataId(sysFlowSHDTO.getDataId());
                            f.setFormUrl(FinFlowFormUrlConstant.REPAYMENT_FORM_URL);
                        }
                    }
                }
                //流程历史填充到 付款申请信息中 end

            }
        }
        //拼接数据 end
    }
}
